﻿using System;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using Caliburn.Micro;
using MvvmEx.Base;

namespace MvvmEx.Command
{
    public class MenuItemCommand : PropertyChangedBase
    {
        #region 字段

        private string _header;
        private RelayCommand<TreeNodeViewModelBase> _command;
        private TreeNodeViewModelBase _commandParameter;
        private Image _icon;
        private ObservableCollection<MenuItemCommand> _children;
        private object _toolTip;

        #endregion


        #region 属性

        public object ToolTip
        {
            get
            {
                return _toolTip;
            }
            set
            {
                if (Equals(value, _toolTip)) return;
                _toolTip = value;
                NotifyOfPropertyChange(() => ToolTip);
            }
        }

        public Image Icon
        {
            get
            {
                return _icon;
            }
            set
            {
                _icon = value;
                NotifyOfPropertyChange(() => Icon);
            }
        }

        public string Header
        {
            get
            {
                return _header;
            }
            set
            {
                _header = value;
                NotifyOfPropertyChange(() => Header);
            }
        }

        public RelayCommand<TreeNodeViewModelBase> Command
        {
            get
            {
                return _command;
            }
            set
            {
                _command = value;
                NotifyOfPropertyChange(() => Command);
            }
        }

        public TreeNodeViewModelBase CommandParameter
        {
            get
            {
                return _commandParameter;
            }
            set
            {
                _commandParameter = value;
                NotifyOfPropertyChange(() => CommandParameter);
            }
        }

        public ObservableCollection<MenuItemCommand> Children
        {
            get
            {
                return _children;
            }
            set
            {
                if (Equals(value, _children)) return;
                _children = value;
                NotifyOfPropertyChange(() => Children);
            }
        }

        #endregion

        public MenuItemCommand()
        {
            Children = new ObservableCollection<MenuItemCommand>();
        }

    }

    public class MenuItemCommand<T> : PropertyChangedBase
    {
        #region 字段

        private string _header;
        private RelayCommand<T> _command;
        private T _commandParameter;
        private Image _icon;
        private ObservableCollection<MenuItemCommand<T>> _children;

        #endregion


        #region 属性

        public Image Icon
        {
            get
            {
                return _icon;
            }
            set
            {
                _icon = value;
                NotifyOfPropertyChange(() => Icon);
            }
        }

        public string Header
        {
            get
            {
                return _header;
            }
            set
            {
                _header = value;
                NotifyOfPropertyChange(() => Header);
            }
        }

        public RelayCommand<T> Command
        {
            get
            {
                return _command;
            }
            set
            {
                _command = value;
                NotifyOfPropertyChange(() => Command);
            }
        }

        public T CommandParameter
        {
            get
            {
                return _commandParameter;
            }
            set
            {
                _commandParameter = value;
                NotifyOfPropertyChange(() => CommandParameter);
            }
        }

        public ObservableCollection<MenuItemCommand<T>> Children
        {
            get
            {
                return _children;
            }
            set
            {
                if (Equals(value, _children)) return;
                _children = value;
                NotifyOfPropertyChange(() => Children);
            }
        }

        #endregion

        public MenuItemCommand()
        {
            Children = new ObservableCollection<MenuItemCommand<T>>();
        }

    }
}